import {createRouter, createWebHashHistory} from "vue-router";
import routes from "./router";
import {showNotify} from "vant";

/*
* 路由配置
* */

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

// 路由守卫
router.beforeEach((to, from) => {
    // 判断是否需要鉴权
    if (!to.meta.isAuth) {
        return
    }

    // 获取token
    const token = localStorage.getItem("token")
    if (token == undefined || token == null) {
        showNotify({type: 'warning', message: '您还没有登陆呢'});
        // 没有登陆
        return {name: "login"}
    }
    return true
})

export default router